#include "alignmentpattern.h"

alignmentpattern::alignmentpattern()
{
    for (int i = 0; i < 5; i++)
        seed[i] = 18+4*i;
    for (int i = 0; i < 7; i++)
    {
        seed2[i][0] = 6;
        seed2[i][1] = 22+2*i;
        seed2[i][2] = 38+4*i;
    }
}

void alignmentpattern::findAlignments(point origin, int versionINFO, int pixelProportion, QImage *img)
{
    pixel p;

    for (int row = 0; row < 5*pixelProportion; row += pixelProportion)
    {
        for (int col = 0; col < 5*pixelProportion; col += pixelProportion)
        {
            if (versionINFO < 7)
                p.paintPixel(seed[versionINFO-2]*pixelProportion+origin.getRow()-2*pixelProportion+row, seed[versionINFO-2]*pixelProportion+origin.getColumn()-2*pixelProportion+col, pixelProportion, qRgb(255,0,0), img);
            else
            {
                p.paintPixel(seed2[versionINFO-7][0]*pixelProportion+origin.getRow()-2*pixelProportion+row, seed2[versionINFO-7][1]*pixelProportion+origin.getColumn()-2*pixelProportion+col, pixelProportion, qRgb(255,0,0), img);
                p.paintPixel(seed2[versionINFO-7][1]*pixelProportion+origin.getRow()-2*pixelProportion+row, seed2[versionINFO-7][0]*pixelProportion+origin.getColumn()-2*pixelProportion+col, pixelProportion, qRgb(255,0,0), img);
                p.paintPixel(seed2[versionINFO-7][1]*pixelProportion+origin.getRow()-2*pixelProportion+row, seed2[versionINFO-7][1]*pixelProportion+origin.getColumn()-2*pixelProportion+col, pixelProportion, qRgb(255,0,0), img);
                p.paintPixel(seed2[versionINFO-7][1]*pixelProportion+origin.getRow()-2*pixelProportion+row, seed2[versionINFO-7][2]*pixelProportion+origin.getColumn()-2*pixelProportion+col, pixelProportion, qRgb(255,0,0), img);
                p.paintPixel(seed2[versionINFO-7][2]*pixelProportion+origin.getRow()-2*pixelProportion+row, seed2[versionINFO-7][1]*pixelProportion+origin.getColumn()-2*pixelProportion+col, pixelProportion, qRgb(255,0,0), img);
                p.paintPixel(seed2[versionINFO-7][2]*pixelProportion+origin.getRow()-2*pixelProportion+row, seed2[versionINFO-7][2]*pixelProportion+origin.getColumn()-2*pixelProportion+col, pixelProportion, qRgb(255,0,0), img);
            }
        }
    }

    if (versionINFO < 7)
        log->addLog("\nALIGNMENTS ENCONTRADOS = 1");
    else
        log->addLog("\nALIGNMENTS ENCONTRADOS = 6");
}

void alignmentpattern::setCanvas(canvas *log)
{
    this->log = log;
}
